package zcw.com.lib_leet_code;

/**
 * Created by 朱城委 on 2021-7-9.<br><br>
 *
 * Excel表列序号
 */
public class Topic171 {

    public static void main(String[] args) {
        Topic171 instance = new Topic171();

        System.out.println(instance.titleToNumber("A"));
        System.out.println(instance.titleToNumber("AB"));
        System.out.println(instance.titleToNumber("ZY"));
        System.out.println(instance.titleToNumber("FXSHRXW"));
    }

    public int titleToNumber(String columnTitle) {
        if(columnTitle == null || columnTitle.length() == 0) {
            return 0;
        }

        int result = 0;
        for(char ch : columnTitle.toCharArray()) {
            result = result * 26 + (ch - 'A' + 1);
        }

        return result;
    }
}
